﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace HCI.Questionaire.Controls
{
    public partial class PopupDialog : UserControl
    {
        public event RoutedEventHandler FirstButtonCliked;
        public event RoutedEventHandler SecoundButtonCliked;

        public string HeaderText
        {
            get
            {
                return this.txtHeader.Text;
            }
            set
            {
                this.txtHeader.Text = value;
            }
        }

        public string BodyText
        {
            get 
            { 
                return this.txtBody.Text; 
            }
            set 
            { 
                this.txtBody.Text = value; 
            }
        }


        public string SecoundButtonText
        {
            get
            {
                return this.btnSecound.Content.ToString();
            }
            set
            {
                this.btnSecound.Content = value;
            }
        }
        public string FirstButtonText
        {
            get
            {
                return this.btnFirst.Content.ToString();
            }
            set
            {
                this.btnFirst.Content = value;
            }
        }



        public PopupDialog(double OriginX, double OriginY, double DestinationX, double DestinationY)
            : this()
        {
            this.OriginX = OriginX;
            this.OriginY = OriginY;

            // this is where the LEFT-BOTTOM X-Y-coördinates will
            // end up - so we adjust these to our liking; in this case,
            // I change 'em so the controls "pops up" in the middle of its parent
            // by adjusting the destination-coördinates by half of its own width/height

            this.DestinationX = DestinationX - ((400 + 40) / 2);
            this.DestinationY = DestinationY - ((200 + 40) / 2);

            // create the correct animation, begin the animation
            Animate.CreateTranslateAndScaleIn(mainBorder, this.OriginX, this.OriginY, this.DestinationX, this.DestinationY).Begin();

        }
        public PopupDialog()
        {
            InitializeComponent();
        }

        // location properties
        public double OriginX { get; set; }
        public double OriginY { get; set; }
        public double DestinationX { get; set; }
        public double DestinationY { get; set; }

        // close this control
        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            // complete animation, "pop me in"
            ClosePopup();
        }

        public void ClosePopup()
        {
            Storyboard sb = Animate.CreateTranslateAndScaleOut(mainBorder, OriginX, OriginY, DestinationX, DestinationY);
            sb.Completed += new EventHandler(sb_Completed);
            sb.Begin();
        }

        void sb_Completed(object sender, EventArgs e)
        {
            // remove control =>
            if (this.Parent != null)
            {
                ((Grid)this.Parent).Children.Remove(this);
            }
        }

        private void btnFirst_Click(object sender, RoutedEventArgs e)
        {
            if (this.FirstButtonCliked != null)
                this.FirstButtonCliked(this, e);
        }

        private void btnSecound_Click(object sender, RoutedEventArgs e)
        {
            if (this.SecoundButtonCliked != null)
                this.SecoundButtonCliked(this, e);
        }
    }
}
